package com.example.recyclevview309wd.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;


import com.example.recyclevview309wd.R;
import com.example.recyclevview309wd.adapter.MyAdapter;
import com.example.recyclevview309wd.bean.TcaseBean;
import com.example.recyclevview309wd.iface.TcaseListener;
import com.example.recyclevview309wd.model.TcaseModel;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;//显示效果
    private MyAdapter adapter;
    private List<TcaseBean> list;
    TcaseListener tcaseListener = new TcaseListener() {
        @Override
        public void onResponse(List<TcaseBean> beanList) {
            list = beanList;
            adapter.setList(list);
            adapter.notifyDataSetChanged();
        }

        @Override
        public void onFile(String msg) {
            Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        //list = getList();
        adapter = new MyAdapter(this);
        adapter.setList(list);
        recyclerView.setAdapter(adapter);

        TcaseModel tcaseModel = new TcaseModel();
        tcaseModel.getResultList("tcase", 2, "rv1l2tidbomann2qn86nln6ur2", tcaseListener);
    }
    /*
    public List<TcaseBean> getList(){
        List<TcaseBean> data = new ArrayList<TcaseBean>();
        TcaseBean TcaseBean1 = new TcaseBean();
        TcaseBean TcaseBean2 = new TcaseBean();
        TcaseBean TcaseBean3 = new TcaseBean();
        TcaseBean TcaseBean4 = new TcaseBean();
        TcaseBean1.setArticleId(1);
        TcaseBean1.setTitle("标题");
        TcaseBean1.setImgid(R.drawable.f1);
        TcaseBean1.setDescription("描述1");
        TcaseBean1.setTime("2017-4-13 11:11");

        TcaseBean2.setArticleId(2);
        TcaseBean2.setTitle("标题");
        TcaseBean2.setImgid(R.drawable.f2);
        TcaseBean2.setDescription("描述2");
        TcaseBean2.setTime("2017-4-13 11:11");

        TcaseBean3.setArticleId(3);
        TcaseBean3.setTitle("标题");
        TcaseBean3.setImgid(R.drawable.f3);
        TcaseBean3.setDescription("描述3");
        TcaseBean3.setTime("2017-4-13 11:11");

        TcaseBean4.setArticleId(4);
        TcaseBean4.setTitle("标题");
        TcaseBean4.setImgid(R.drawable.f4);
        TcaseBean4.setDescription("描述4");
        TcaseBean4.setTime("2017-4-13 11:11");

        data.add(TcaseBean1);
        data.add(TcaseBean2);
        data.add(TcaseBean3);
        data.add(TcaseBean4);

        return data;
    }
    */
}
